// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
const db = uniCloud.database();
const dbCmd = db.command
const uniID = require('uni-id-common')
module.exports = {
	_before: function() { // 通用预处理器
		const clientInfo = this.getClientInfo()
		this.uniID = uniID.createInstance({ // 创建uni-id实例，其上方法同uniID
			clientInfo
		})
	},
	async getUserInfoById(user_id) {
		const userinfo = await db.collection('uni-id-users').where({
			_id: user_id
		}).field({
			username: true,
			nickname: true,
			article_likes_ids: true,
			last_login_date: true,
			last_login_ip: true,
			_id: true,
			avatar_file: true
			// 其他你需要的字段
		}).get();
		console.log(userinfo)
		// 返回数据给客户端
		return {
			code: 200,
			msg: '数据请求成功',
			data: userinfo.data[0]
		};
	},

	async getUserId(token) {
		const res = await this.uniID.checkToken(token)
		return {
			code: 200,
			msg: '数据请求成功',
			data: res
		}
	}
}